﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
using EIIS.FrameWork.DomainModel;
using EIIS.FrameWork;
using EIIS.FrameWork.Attributes;

namespace EIIS.Infrastructure.Model.System.Authority
{
    /// <summary>
    /// 系统用户的基类
    /// </summary>
    public class Person : InputItem
    {
        /// <summary>
        /// 登录名
        /// </summary>
        public virtual string LoginName { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        public virtual string Pwd { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public virtual string Description { get; set; }

        /// <summary>
        /// 用户状态
        /// </summary>
        public virtual PersonState State { get; set; }

        /// <summary>
        /// 用户所在角色
        /// <remarks>一个用户可能具有多个角色</remarks>
        /// </summary>
        public virtual Iesi.Collections.Generic.ISet<Role> Roles { get; set; }

        /// <summary>
        /// 用户常用菜单
        /// </summary>
        public virtual Iesi.Collections.Generic.ISet<MenuNode> FavoriteMenus { get; set; }

        /// <summary>
        /// 获取pwd参数的MD5编码
        /// </summary>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public static string GetPwdMD5(string pwd)
        {
            return FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5");
        }
    }

    /// <summary>
    /// 用户状态
    /// </summary>
    public enum PersonState
    {
        [EnumDescription("正常")]
        Normal = 0,

        [EnumDescription("停用")]
        Disabled = 1
    }
}
